package vcp.gui.forms;

import javax.swing.JOptionPane;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;

import vcp.gui.components.VCPPanel;
import vcp.gui.forms.validators.NumericValidator;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TrackOrderForm extends VCPPanel {
	private JLabel lblTrackFormError;
	private JTextField textOrderID;
	private boolean isFormValid=false;

	/**
	 * Create the panel.
	 */
	public TrackOrderForm() {
		
		JLabel lblOID = new JLabel("Order ID");
		
		textOrderID = new JTextField();
		textOrderID.setColumns(10);
		lblTrackFormError = new JLabel("");
		lblTrackFormError.setForeground(Color.RED);
		
		JButton btnTrackOrder = new JButton("track");
		btnTrackOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				NumericValidator validator = new NumericValidator();
				if(!validator.validate(textOrderID.getText())){
					lblTrackFormError.setText("Form error ...");
				}else{
					JOptionPane.showMessageDialog(null, "order id:#"+textOrderID.getText()+" info ...");
				}
				
			}
		});
		
		
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblOID)
							.addGap(35)
							.addComponent(textOrderID, GroupLayout.PREFERRED_SIZE, 243, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(btnTrackOrder))
						.addComponent(lblTrackFormError))
					.addContainerGap(21, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addComponent(lblTrackFormError)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblOID)
						.addComponent(textOrderID, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnTrackOrder))
					.addContainerGap(275, Short.MAX_VALUE))
		);
		setLayout(groupLayout);

	}
}
